-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: make sure plugin logger sets context #13201
base: main
Are you sure you want to change the base?
Conversation
what was meant was likely to do a `self.class.logger` here
also changes the contract from msg.to_str to msg.to_s
also improves performance of plugin.logger invocations
... for restore to keep the previously set id
# TODO do we want to keep this around due plugin specs mocking logger through the class.logger call?! | ||
# | ||
# @override LogStash::Util::Loggable.logger | ||
# @private | ||
# def self.logger(plugin = nil) | ||
# plugin.nil? ? super() : LogStash::Logging::PluginLogger.new(plugin) | ||
# end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately, some existing plugin specs assume SomePlugin.logger
class method to return the logger used for the plugin instance. the class level call still works (instantiates a new logger) but since we want the logger
instance to keep context it needs the plugin instance passed in (for correctness).
my approach would be to deal with the broken specs afterwards and not introduce hacks such as these ...
# TODO do we want to keep this around due plugin specs mocking logger through the class.logger call?! | |
# | |
# @override LogStash::Util::Loggable.logger | |
# @private | |
# def self.logger(plugin = nil) | |
# plugin.nil? ? super() : LogStash::Logging::PluginLogger.new(plugin) | |
# end |
Improves logging experience for the user (commits extracted from #13038).
logger(msg)
contract allows for logging any (to_s
) message not just strings - just like Log4j2 loggers doPluginLogger
gets introduced to always have aplugin.id
logging context(with
logger.debug ...
etc.)Other changes:
logger.trace?
(previously delegated tologger.isDebugEnabled()
)Breaking changes:
def class.logger(plugin = self)
functional in a backwards compatible wayWhy is it important/What is the impact to the user?
Logs are Logstash's primary way of communicating with the user, always having a plugin id logged greatly improves the user (debugging) experience.
Release notes
We improved logging from plugins to always include contextual information (plugin's id) in logs.
What does this PR do?
A new
PluginLogger
is introduced, which is now unique per plugin instance.Why is it important/What is the impact to the user?
Users will have better context when going through logs - as they should see the plugin id (which might be user set) more often.
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration files (and/or docker env variables)Author's Checklist
[DEBUG][logstash.codecs.line ][line_cec86de4-b9b7-44ce-95c4-63423b9f92c3]
to resolve this we we need to do further changes, either:
Plugin
base class (concerns testing)CodecClass.new
instantiation with an explicit id paramHow to test this PR locally
e.g.
bin/logstash --log.level debug -e ""
will doRelated issues
Logs